 package uuengine.engine.event;

import java.util.Vector;

public class EventDispatcher {
	
	protected Vector eventListener = null;
	public void addEventListener(EventListener listener) {
		if (listener == null) {
			throw new NullPointerException("EventObserver can't be null");
		}
		if (eventListener == null) {
			eventListener = new Vector();
		}
		eventListener.addElement(listener);
	}

	public void dispatchEvent(Event e) {
		if (eventListener != null) {
			int size=eventListener.size();
			for (int i = 0; i < size; i++) {
				((EventListener) (eventListener.elementAt(i))).handlerEvent(e);
			}
		}
	}

	public void removeEventListener(EventListener listener) {
		if (eventListener != null) {
			if (eventListener.contains(listener)) {
				eventListener.removeElement(listener);

			}
		}
	}

	public void clearObserver() {
		if (eventListener != null) {
			eventListener.removeAllElements();
			eventListener = null;
		}
	}
}
